***********************************************
* Rwanda provider study
***********************************************

***********************************************
* Contents
***********************************************

	* (0.0) Set up
	* (0.1) Regressions: Gen phys resources and gen operations
	* (0.2) Regressions: Del phys resources and del operations
	* (0.3) Regressions: Delivery HR and general HR	
	* (0.4) Supplementary Regressions: Staff

**************************************************************
* (0.0) Set up
**************************************************************
	
	clear all
	clear matrix
	set mem 250m
	set matsize 1000
	set more off
	tempfile temp1
	pause on
    eststo clear
	
	cd "C:\Users\Diana\Dropbox\RWA_P4P\SPA\do_files"
	do rwanda_global_define.do

    cap log close
    log using `"$d_out\logs\logresults_`c(current_date)'.txt"', text replace

**************************************************************
* (0.1) Regressions: Gen phys resources and gen operations
**************************************************************

use "$d_interm\manage_mult", clear
merge 1:1 facil using "$r_fac_controls", nogen

local genphys="q_basicsupplies q_basicequip"
local genop="cl_clean manage_mult"
foreach var in `genphys' `genop' {
	egen max_`var'=max(`var')
	egen min_`var'=min(`var')
	* Normalizing to be fraction of achievement
	gen `var'_maxed=(`var'-min_`var')/(max_`var'-min_`var')
}

local clean_infra="cl_soap cl_disin cl_incin cl_watsource cl_wat cl_steril q_bedpc q_elec q_basicsupplies q_basicequip"
local manage_mult="m_mmin m_cmin m_hmis m_qmin m_equip m_avail m_wait cl_clean cl_org clean_mult manage_mult"
local clean_pca="q_supplies_pca q_equip_pca"
local manage_mult_pca "cl_clean_pca m_wait manage_mult_pca cl_clean_sc cl_clean_sc_pca"

gen index_gphys=0.5*q_basicsupplies_maxed+0.5*q_basicequip_maxed
global index_gphys_desc "General physical resources, EQ/EQ"

gen idx_gphys_eqpca=0.5*q_supplies_pca+0.5*q_equip_pca
global idx_gphys_eqpca_desc "General physical resources"

pca q_supplies_pca q_equip_pca if treatment==0
predict index_gphys_pca
global index_gphys_pca_desc "General physical resources, PCA"

gen index_gmanage=1/3*cl_clean_maxed+1/3*manage_mult_maxed+1/3*m_wait
global index_gmanage_desc "General operations, EQ/EQ"

gen idx_gman_eqpca=1/3*cl_clean_pca+1/3*manage_mult_pca+1/3*m_wait
global idx_gman_eqpca_desc "General operations"

pca cl_clean_pca manage_mult_pca m_wait if treatment==0
predict index_gman_pca
global index_gman_pca_desc "General operations, PCA"


rwanda_regressions `clean_infra' index_gphys, savename("clean_infra") title("General physical resources")
rwanda_regressions `manage_mult' index_gmanage, savename("manage_mult") title("General operational inputs")
rwanda_regressions `clean_pca' index_gphys_pca idx_gphys_eqpca, savename("clean_pca") title("Clean PCA indices")
rwanda_regressions `manage_mult_pca' index_gman_pca idx_gman_eqpca, savename("manage_mult_pca") title("Manage mult PCA indices")

**************************************************************
* (0.2) Regressions: Del phys resources and del operations
**************************************************************


use "$d_interm\del_mult", clear
merge 1:1 facil using "$d_interm\inputs", nogen
merge 1:1 facil using "$r_fac_controls", nogen


local del_equip="q_bedscaled q_bedstarget d_table d_instr d_asp d_steth d_thread d_light d_iscale d_edrops d_anesth"
local del_equip="`del_equip' d_gloves d_clamp q_delambul d_equip del_mult q_ambul q_obstetambul"
local del_med="q_utero q_antibi q_magne q_diaz q_skindis q_iv q_medwho q_phys q_phys_pca"
local del_mult="d_priv days_anc q_24hcov q_delmonitor q_delmeet q_delstat q_advmeet"
local del_mult_pca="d_priv days_anc q_24hcov q_delmon_pca"

foreach var in q_bedscaled days_anc q_phys q_delmonitor {
	egen max_`var'=max(`var')
	egen min_`var'=min(`var')
	* Normalizing to be fraction of achievement
	gen `var'_maxed=(`var'-min_`var')/(max_`var'-min_`var')
}

gen index_dphys=1/3*q_bedscaled_maxed+1/3*q_phys_maxed+1/3*q_obstetambul
global index_dphys_desc "Delivery physical resources, EQ/EQ"

gen idx_dphys_eqpca=1/3*q_bedscaled_maxed+1/3*q_phys_pca+1/3*q_obstetambul
global idx_dphys_eqpca_desc "Delivery physical resources"

pca q_bedscaled_maxed q_phys_pca q_obstetambul if treatment==0
predict index_dphys_pca
global index_dphys_pca_desc "Delivery physical resources, PCA"

gen index_dmanage=1/3*days_anc_maxed+1/3*q_delmonitor_maxed+1/3*d_priv
global index_dmanage_desc "Delivery operations, EQ/EQ"

gen idx_dman_eqpca=1/3*days_anc_maxed+1/3*q_delmon_pca+1/3*d_priv
global idx_dman_eqpca_desc "Delivery operations"

pca days_anc_maxed d_priv q_delmon_pca if treatment==0
predict index_dman_pca
global index_dman_pca_desc "Delivery operations, PCA"

rwanda_regressions `del_equip' index_dphys index_dphys_pca idx_dphys_eqpca, savename("del_equip") title("Delivery-specific physical resources---Equipment")
rwanda_regressions `del_med', savename("del_med") title("Delivery-specific physical resources---Medications")
rwanda_regressions `del_mult' index_dmanage, savename("del_mult") title("Delivery-specific operations")
rwanda_regressions `del_mult_pca' index_dman_pca idx_dman_eqpca, savename("del_mult_pca") title("Delivery-specific operations")

**************************************************************
* (0.3) Regressions: Delivery HR and general HR
**************************************************************

use "$d_interm\inputs", clear
merge 1:1 facil using "$r_fac_controls", nogen
merge 1:1 facil using "$d_interm\avg_hr"

local del_staff "fancppc chw_del amidwifepc q_docnightday"
local gen_staff "astaffpc allstaffppc"

foreach var in fancppc amidwifepc astaffpc allstaffppc avg_hr {
	egen max_`var'=max(`var')
	egen min_`var'=min(`var')
	* Normalizing to be fraction of achievement
	gen `var'_maxed=(`var'-min_`var')/(max_`var'-min_`var')
}

global amidwifepc_desc "No. midwives/10,000 people"
lab var amidwifepc "$admiwifepc_desc"

global astaffpc_desc "No. staff/10,000 people"
lab var astaffpc "$astaffpc_desc"

gen index_dhr=0.25*fancppc_maxed+0.25*chw_del+0.25*amidwifepc_maxed+0.25*q_docnightday
global index_dhr_desc "Delivery human resources"

pca fancppc_maxed chw_del amidwifepc_maxed q_docnightday if treatment==0
predict index_dhr_pca
global index_dhr_pca_desc "Delivery human resources, PCA" 

gen index_ghr=1/3*astaffpc_maxed+1/3*allstaffppc_maxed+1/3*avg_hr_maxed
global index_ghr_desc "General human resources"

pca astaffpc_maxed allstaffppc_maxed avg_hr_maxed if treatment==0
predict index_ghr_pca
global index_ghr_pca_desc "General human resources, PCA"

rwanda_regressions `del_staff' index_dhr index_dhr_pca, savename("del_staff") title("Delivery-specific human resources")
rwanda_regressions `gen_staff' index_ghr index_ghr_pca, savename("gen_staff") title("General human resources")


**************************************************************
* (0.4) Supplementary Regressions: Staff
**************************************************************
	

use "$d_interm\inputs", clear
merge 1:1 facil using "$r_fac_controls", nogen

local staff_list1="astaffpc adocpc anursepc amidwifepc amedoffpc ahealthasspc atechpc anutrpc"
local staff_list2="asocpc apharmpc aspecpc amanagepc atechsuppc amansuppc aothermedpc aothersuppc"

rwanda_regressions `staff_list1', savename("staff_list1") title("Staff, subgroup 1")
rwanda_regressions `staff_list2', savename("staff_list2") title("Staff, subgroup 2")

local mstaff_list1="mstaffpc mdocpc mnursepc mmidwifepc mmedoffpc mhealthasspc mtechpc mnutrpc"
local mstaff_list2="msocpc mpharmpc mspecpc mmanagepc mtechsuppc mmansuppc mothermedpc mothersuppc"

rwanda_regressions `mstaff_list1', savename("mstaff_list1") title("Male staff, subgroup 1")
rwanda_regressions `mstaff_list2', savename("mstaff_list2") title("Male staff, subgroup 2")

local fstaff_list1="fstaffpc fdocpc fnursepc fmidwifepc fmedoffpc fhealthasspc ftechpc fnutrpc"
local fstaff_list2="fsocpc fpharmpc fspecpc fmanagepc ftechsuppc fmansuppc fothermedpc fothersuppc"

rwanda_regressions `fstaff_list1', savename("fstaff_list1") title("Female staff, subgroup 1")
rwanda_regressions `fstaff_list2', savename("fstaff_list2") title("Female staff, subgroup 2")

local pstaff_list1="pstaffpc pdocpc pnursepc pmidwifepc pmedoffpc phealthasspc ptechpc pnutrpc"
local pstaff_list2="psocpc ppharmpc pspecpc pmanagepc ptechsuppc pmansuppc pothermedpc pothersuppc"

rwanda_regressions `pstaff_list1', savename("pstaff_list1") title("Part time staff, subgroup 1")
rwanda_regressions `pstaff_list2', savename("pstaff_list2") title("Part time staff, subgroup 2")

local fte_staff_list1="fte_staffpc fte_docpc fte_nursepc fte_midwifepc fte_medoffpc fte_healthasspc fte_techpc fte_nutrpc"
local fte_staff_list2="fte_socpc fte_pharmpc fte_specpc fte_managepc fte_techsuppc fte_mansuppc fte_othermedpc fte_othersuppc"

rwanda_regressions `fte_staff_list1', savename("fte_staff_list1") title("Full time staff, subgroup 1")
rwanda_regressions `fte_staff_list2', savename("fte_staff_list2") title("Full time staff, subgroup 2")
